[MongoDB] Query to Get Documents Where a Specific Text Field Has x or More Characters

Tadashi Shigeoka ·  Wed, October 22, 2014

I’ll introduce a query to get documents where a specific text field has x or more characters in MongoDB.

MongoDB | モンゴディービー

db.users.find( { name : { $ne: null }, $where: "this.name.length > 5" } )

The key point is checking the length with $where only when the name field has a value.

That’s all from the Gemba.