mongodb - Mongo. how to check if field is a number -


how select mongodb documents field number?

some examples of content of field: "2", "a", "z", 3

you can use $type operator select based on bson type of field, should want.

so, example, find strings:

db.collection.find( { field: { $type : 2 } } ) 

or, find doubles (which numbers stored shell default javascript behavior), use:

db.collection.find( { field: { $type : 1 } } ) 

since there 2 types of integer (potentially) need go this:

db.collection.find({$or : [{"field" : { $type : 16 }}, {"field" : { $type : 18 }}]}) 

finally then, numbers, integer or double:

db.collection.find({$or : [{"field" : { $type : 1 }}, {"field" : { $type : 16 }}, {"field" : { $type : 18 }}]}) 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -