Monday, 15 March 2010

nosql - Replace the use of $where in MongoDB -



nosql - Replace the use of $where in MongoDB -

i have question, need compare if partition of 2 fields greater or equal value. solution i've found is:

{ "$where": "this.total / this.limit > 0.6" }

but docs says utilize of $where isn't performance, because run javascript function, , lose indexes.

does has improve solution this, doesn't utilize $where?

thanks !

you move aggregation framework here using split ( http://docs.mongodb.org/manual/reference/aggregation/#_s_divide ):

db.col.aggregate([ {$match: {_id: whatever_or_whatever_clause_you_want}}, {$project: { // document fields divided_limit: {$divide: ['$total', '$limit']} }}, {$match: {divided_limit: {$gt: 0.6}}} ]);

note: aggregation framework new since v2.1

but docs says utilize of $where isn't performance, because run javascript function, , lose indexes

you can't utilize index anyway, there no way utilize index mathematical functions this. key thing js engine 16x slower normal querying, aggregation framework should faster. not js lock global queries.

of course of study fastest method pre-aggregate sum field upon modifying record in application, won't need of this, normal query.

mongodb nosql mongodb-php mongodb-query

No comments:

Post a Comment