₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,273 members, 8,430,141 topics. Date: Friday, 19 June 2026 at 11:08 PM

Toggle theme

Mongodb Nodejs Help Needed ASAP! - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingMongodb 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
}
});
1 Reply

Discussion: What Is Your Opinion Of MongodbExperienced Mongodb/nodejs Backend Developer NeededThreaded/nested Comment System Using Mongodb234

Btc Investment Script AvailableLearn How To Code Android, Build Web Service With PHP And How To Host A Website.Hack Nairaland