Mongodb Nodejs Help Needed ASAP! - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Mongodb Nodejs Help Needed ASAP! (1036 Views)
1 Reply
| Mongodb Nodejs Help Needed ASAP! by Nobody: 1:32pm On Nov 26, 2017 |
MongoDB just wasted my 1 hour! I want to create Collection from the front end (through user submitted form). The problem is I just can't find a way to CHECK IF THE COLLECTION ALREADY EXIST. I'm using nodeJs and I want something like: if( collectionExists(collectionTitle) ) //boolean: true Please, is there such solution or any solution at all? I have tried tricks like: if(collectionTitle.find({field: value}).count() !== 'undefined') // This throws error I know there are work around like forcing the user to select from existing Collection and only try to create it if it doesn't exist. I don't want to use that. |
| Re: Mongodb Nodejs Help Needed ASAP! by Nobody: 3:40pm On Nov 26, 2017 |
I'm just a beginner i think you can have a variable somewhere that holds the lisT the names of any collection created .. So that when A user from the frontend whats to create a collection , you program just searches through the list to chech if it exist .. |
| Re: Mongodb Nodejs Help Needed ASAP! by BlueMagnificent(m): 7:47pm On Nov 28, 2017 |
Try this db.listCollections({name: collName}) .next(function(err, collinfo) { if (collinfo) { // The collection exists } }); |
Discussion: What Is Your Opinion Of Mongodb • Experienced Mongodb/nodejs Backend Developer Needed • Threaded/nested Comment System Using Mongodb • 2 • 3 • 4
Btc Investment Script Available • Learn How To Code Android, Build Web Service With PHP And How To Host A Website. • Hack Nairaland