如何使用数组对象在mongoDB中保存记录

时间:2019-09-02 03:07:57

标签: node.js mongoose

使用MongooseJS模块将以下对象另存为mongodb中的记录。

const object = {
    num: 'IVN21034',
    date: '2019/09/02',
    lines: [{
            item_id: 1,
            qty: 1,
            price: 10
        }, {
            item_id: 2,
            qty: 1,
            price: 10
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

const mongoose = require('mongodb').MongoClient,
        db = "dburl";
        dbo = mongoose.connect(db),
        response = await dbo.collection("<tablename>").insertOne(<object to be inserted>);