Thursday, June 27, 2013

MongoDB low level querying through grails mongodb plugin


This example displays MongoDB querying on multiple fields with multiple filters on any given field using grails MongoDB Plugin

Fetch all the people who have their lastName as "spencer" but their firstName must not be 'Mark' with salary between 10000 and 30000.

Person.collection.find('lastName':'Spencer',firstName: ['$ne':'Mark'], salary: ['$gt':10000, '$lt':30000])

Note:

We need to use single quotes while writing $gt, $ne, $lt etc because if we use double quote then grails tries to evalue $gt and hence results in error




No comments:

Post a Comment