简体   繁体   English

猫鼬创建文档并创建批处理子文档

[英]Mongoose Create a Document and Create Batch Subdocuments

var mongoose = require('mongoose');
var AdressListSchema= new mongoose.Schema({
        id:String,
        name: String,
        adress:String
});

var UserSchema = new mongoose.Schema({
    deviceType: String,
    tokenId: String,
    createDate: { type: Date, default: Date.now }, 
    AdressList: [AdressListSchema]
});
mongoose.model('User',UserSchema );
module.exports = mongoose.model('User');




router.post('/user', function(req, res){
    User.create({
        deviceType :req.body.deviceType,
        tokenId :req.body.tokenId,
        AdressList:[{ name: req.body.name, adress: req.body.adress }]
    },
    function(err, User){
        if(err) return res.status(500).send('fail');
    res.status(200).send(User);
    });
});

The above is a schema that fulfills the requests that exist under the schema present and works successfully, so I don't want to add the sub-document to the records that I actually want to do in bulk. 上面的模式可以满足存在的模式下的请求,并且可以成功运行,因此,我不想将子文档添加到我实际上要批量执行的记录中。 So during a Document Registration I have more than one address to be recorded at the same time and I have no idea how to post it, and I apologize for my english. 因此,在文件注册期间,我同时要记录多个地址,并且我不知道如何张贴该地址,我为此致歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM