mongoose-schema

    1熱度

    1回答

    我對NoSQL世界是全新的,並且很難圍繞它進行思考。這一週,我正在學習的MongoDB(貓鼬)用Node.js的,這裏是我的當前模式: var eventDataSchema = new Schema({ _id : Number, notes : {type: String, required: true}, start_date : {type: Date,

    0熱度

    1回答

    如何將單個子文檔添加到貓鼬文檔中?考慮下面的腳本寫在腳本中: ParentSchema: Schema = new Schema({ name: String, child: ChildSchema }); ChildSchema: Schema = new Schema({ name: String }); 我想添加一個新的孩子父母,只要我創建一個新的父

    2熱度

    1回答

    我正在使用mongodb在節點js中構建應用程序。我使用貓鼬作爲ODM。 問題是我有很多靜態函數附加到模式的貓鼬模型。 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var ObjectId = Schema.Types.ObjectId; var userSchema = new Sch

    0熱度

    3回答

    我想創建模式,其中body可以根據進入的事件有它不同的密鑰。所以當我嘗試呈現數據時,只需將_id發送給客戶端event不是結果的一部分。我用這種方法實施了錯誤的模式嗎? event.model.js var mongoose = require('bluebird').promisifyAll(require('mongoose')); var bmpEventSchema = new mo

    0熱度

    1回答

    我得到了這樣的事情: let fooSchema = new mongoose.Schema({ bars: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Bar' }], }); 和 let barSchema = new mongoose.Schema({ sth1: String, sth2: String,

    0熱度

    1回答

    假設我想要一個數據模式:每個用戶可以有多個筆記本電腦,並且有些筆記本電腦可用。 我希望我可以得到一些架構一樣, User | userId: 1 | laptops: | laptopId: 1 available: true //default | laptopId: 2 available: true 我如何定義這種模式? 以下是不正確的: const User =

    -1熱度

    1回答

    予定義的模型如下面提及: var QuestionSchema = new Schema({ askedBy: {type:ObjectId, Ref:'User'}, relatedCourses: [ {type: ObjectId, ref:'Course'} ] }) module.exports = mongoose.model('Question', Questio

    0熱度

    1回答

    我想按順序執行4個函數。每個功能都是以下格式。像創建更新刪除和顯示。我想在完成其他3個功能後調用顯示功能。我嘗試了承諾方法,但沒有任何數據庫調用它按順序工作。當發生貓鼬呼叫時,訂單正在變化。 function createProjects(req) { var projects = req.body.created; projects.forEach(function (project) {

    3熱度

    1回答

    我有一個貓鼬綱要Employee。在這裏,我想爲員工存儲一個與辦公室相關的字段(電話號碼),只有他/她有資格上班時,只有「高級」和「c級」兩個級別。 的模式: const mongoose = require('mongoose'); const Schema = mongoose.Schema; var EmployeeSchema = new Schema({ name: Str

    1熱度

    2回答

    我正在使用帶bcrypt的預保存鉤子來加密系統上的密碼。在創建或更改密碼時它工作正常。問題在於,每次更改並保存不同的字段時,似乎都會重新加密密碼,例如電子郵件。 可能更容易用代碼解釋。這裏的模型: const UserSchema = new Schema({ email: { type: String, required: true, lowerca