Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,214 members, 7,829,351 topics. Date: Thursday, 16 May 2024 at 04:09 AM

Mongodb Nodejs Help Needed ASAP! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Mongodb Nodejs Help Needed ASAP! (960 Views)

Discussion: What Is Your Opinion Of Mongodb / Experienced Mongodb/nodejs Backend Developer Needed / Threaded/nested Comment System Using Mongodb (2) (3) (4)

(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 Like

(1) (Reply)

Take IT Courses In India For 3 Months / How To Setup Auto Response On Gmail Account / In Need Of An Android App Developer

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 6
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.