Last active
December 2, 2015 17:45
-
-
Save cahlan/ab524b5dad979b7997ef to your computer and use it in GitHub Desktop.
some sample mongodb/mongoose queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//given this schema ... | |
// { | |
// [id] | |
// name: String, | |
// email: String, | |
// bio: String, | |
// createdAt: Date, | |
// age: 11 | |
// } | |
//order these queries from least efficient to most efficient | |
User.findOne({createdAt: {'$gt': new Date(2015, 02, 12)}}).exec(); | |
User.findOne({_id: 'aasldkjflkj324'}).exec(); | |
User.find({name: function(name) { return name.charAt(0) === 'F'; }}).exec(); | |
User.findOne({bio: new RegExp('some phrase', 'g').exec(); | |
User.findOne({name: new RegExp('^F'}).exec(); | |
User.findOne({age: 12}).exec(); | |
User.findOne({name: function(name) { return name.charAt(0) === 'F'; }}).exec(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment