Array positional operators

The concept of array positional operators come from mongodb. Positional operators allow you to project a specific element in an array based on the query criteria specified. Nodechef supports two positioanl operators which are the single position projector ($) and the multi position projector ($*)

Single position projector ($)

This projector allows you to project a single element from an array using the query predicate specified. The query returns the first element in the given array that matches the predicate. Unlike mongodb, the Nodechef single position projector can project elements nested multiple levels in an array.

{ "_id" : 1 "name" : "Dave Gahan" "medications" : [ { "id" : 23, "name" : "Dilaudid", "type" : "Rx", "prescriptions" : [ { "id" : 77, "quantity" : 45, "started" : 2009-02-01 } ] }, { "id" : 41, "name" : "Oxycodone", "type" : "Rx", "prescriptions" : [ { "id" : 77, "quantity" : 45, "started" : 2009-02-01 } ] } ] } SELECT _id, name, medications.prescriptions.$ as p FROM patients WHERE medications.id = 23 AND medications.prescriptions.id = 77 The above query will return the below document { "_id" : 1, "name" : "Dave Gahan", "p" : [ { "id" : 77, "quantity" : 45, "started" : 2009-02-01 } ] }

Multi position projector ($*)

This operator can be used to project multiple elements that match the query critera

{ "_id" : ObjectId("4d2d8deff4e6c1d71fc29a07"), "user_id" : "714638ba-2e08-2168-2b99-00002f3d43c0", "events" : [ { "handled" : 1, "profile" : 10, "data" : { } } { "handled" : 1, "profile" : 10, "data" : { } } { "handled" : 0, "profile" : 20, "data" : { } } ... ] } Consider the above document. If one wants to query for all events sub documents where the events.handle equals 1, the $* operator can be used to accomplish this. SELECT _id, events.$* as handled_events FROM devices WHERE events.handled = 1 The above query will return the below document. { "_id" : ObjectId("4d2d8deff4e6c1d71fc29a07"), "handled_events" : [ { "handled" : 1, "profile" : 10, "data" : { } } { "handled" : 1, "profile" : 10, "data" : { } } ] } SELECT _id, events.$*.profile as events_profile FROM devices WHERE events.handled = 1 The above query returns the below document. { "_id" : ObjectId("4d2d8deff4e6c1d71fc29a07"), "events_profle" : [ 10, 10 ] }