addToSet mongo更新文档

时间:2015-11-12 14:52:31

标签: mongodb insert-update

我有两个模式。

tables.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var SchemaOne = new Schema({
    TheDate: { type: String },
    ThePiece: {type: String }
}, { versionKey: false });

var SchemaTwo = new Schema({
    UrlLink: { type: String },
    Name: { type: String },
    Type: { type: String },
    Thing: { type: String },
    NewInfo: [SchemaOne]
}, { versionKey: false });

module.exports = mongoose.model('tables', SchemaTwo);

然后我导入上面的文件:

var ThisTable = require("../models/tables.js");

然后我尝试更新NewInfo对象(如果满足某些条件):

ThisTable.update({ UrlLink: Myurl }, {
    $addToSet: {
       "NewInfo": {
           TheDate: ThisDate,
           ThePiece: ThisPiece
        }
    }
});

我做错了吗?因为脚本崩溃而我无法通过远程计算机的某些限制进行调试。

0 个答案:

没有答案
相关问题