Operators: $order
Ensuring documents are inserted neatly.
🪶 The $order
operator is used to ensure that data is inserted into the collection in an orderly manner according to the insertion date.NOTE: $order is not an operator in itself, but it falls into this category, you use the option ordered to guarantee or not that $order is assigned to a document.
1 import MerlinDB, { Schema} from "@chrisaxxwell/merlin-db";2 //Or if you are using 'merlindb.max.js' just call 'new MerlinDB()'; 3 4 const merlin = new MerlinDB( ) ;5 merlin.connect( "Client") ; 6 var clientModel = merlin.model( "Users", <userSchema>) ;7 8 clientModel.insert( { 9 name: { 10 given: "Samantha", 11 family: "Smith", 12 } , 13 email: 'sam@gmail.com', 14 age: 25 , 15 }, {ordered: true }) //Or 'false' to not sort 16 17 COLLECTION: Users > [18 { 19 name: { given: "Samantha", family: "Smith"} , 20 email: 'sam@gmail.com', 21 age: 25 , 22 $order: 1511512533350 23 id_: "12E2arWEa..." 24 } 25 ... 26 ]