ItGo.me Focus on IT Recommend

Home > node.js - how to create the collection in mongodb without any document using mongoose in nodejs

node.js - how to create the collection in mongodb without any document using mongoose in nodejs

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1074

【阿里云】双十一活动,全年抄底价,限时3天!(老用户也有),
入口地址https://www.aliyun.com/1111/home

I have tried to copy collections from first db to second db, collections those having documents are copied from first db to second db, but collections with no documents are not getting copied. when I tried to create new collection with empty document, collection gets created with one document containing id field.But my requirement is to create collection without any document in mongodb using mongoose.How to create empty collection in MongoDb using mongoose library and node.js. here goes the code

var data = db.model('name', 'mymodel',"collectionName"),
   newCollection = new data({});
   newCollection .save(function (err) {});
node.js mongodb mongoose
edited May 9 '15 at 4:57 asked May 9 '15 at 4:37 Nandhini 6 3      Could you please show some code so we can see what you have already tried? –  michaelpri May 9 '15 at 4:39      var data = db.model('name', 'mymodel',"collectionName"), newCollection = new data({}); newCollection .save(function (err) {}); when new data({}) is used new collection created with one document field containing _id. how to create empty collection? –  Nandhini May 9 '15 at 4:52 1   Can you edit it into your question? –  michaelpri May 9 '15 at 4:53      Just do a db.createCollection('name') - it will create an empty collection without an id. –  Nagasimha Iyengar May 12 '15 at 23:31      need to create collection using mongoose in nodejs –  Nandhini May 13 '15 at 14:11  |  show more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Recommend:node.js - copy a variable from a collection to another one in MongoDB using mongoose and nodeJS

e wrote these lines of code extracting a specific object from the collection ImageAdmin in MongoDB, but when i try to add it to my collection User, i find it "categorie2" : "[object Object]" and the variable categories is undefined. How can

------splitte line----------------------------