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
Post a Comment