node.js - MongoDB/Mongoose: Query for valid document property -


using mongoose mongodb store several collections of data defined each mongoose schema.

1) there easy way (without explicitly querying database) find out whether specific property part of particular collection schema model?

lets have collection of users, including information name , address. @ runtime - mistake - receive data supposed stored in user's document not (fully) comply schema (e. g. shoe size included).

2) know mongoose refuses save data set in case how , @ sort of feedback report appropriately client?

i think fastest way check whether collection contains documents have field mention run count query $exists operator on each collection:

db.collection1.count({ field: { $exists: true }}); db.collection2.count({ field: { $exists: true }}); db.collection3.count({ field: { $exists: true }}); 

afterwards, can save return value of each count operation in variable , pass client, making possible convey message end-user.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -