Skip to content

Crud Operations with provenDB (MongoDB+Blockchain)

License

Notifications You must be signed in to change notification settings

BCDevs/provenDB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ProvenDB-crud

crud operations using provenDB(MongoDB+Blockchain) node and express

  1. insertOne() : Inserts a single document into a collection.
db.products.insertOne( { item: "card", qty: 15 } ); 
# products is the collection name in db
  1. insertMany() : Inserts multipe document into a collection.
db.products.insertMany( [
      { item: "card", qty: 15 },
      { item: "envelope", qty: 20 },
      { item: "stamps" , qty: 30 }
   ] );
} 
  1. insert(): Inserts a single as well as multiple documents into a collection.
db.products.insert( { _id: 10, item: "box", qty: 20 } )

db.products.insert(
   [
     { _id: 11, item: "pencil", qty: 50, type: "no.2" },
     { item: "pen", qty: 20 },
     { item: "eraser", qty: 25 }
   ]
)
  1. find() :The find() method with no parameters returns all documents from a collection and returns all fields for the documents.
db.products.find() //returns all documents in products collection
db.products.find({"item":"pen"}) //returns all "item" named "pen"
  1. findOne(): returns first matching document of query params
db.products.findOne({"item":"card","qty":"15"}) // returns first card item with a qty of 15
  1. updateOne(): Modifies an existing document or documents in a collection. The method can modify specific fields of an existing document or documents or replace an existing document entirely, depending on the update parameter.
db.products.update(query, update, options) // SYNTAX

db.products.update(
   { qty: { $lte: 10 } }, 
   { $set: { reorder: true } },
   { multi: true } 
)

//finds document quantity(qty) is lessthan or equal($lte) to 10
 // updates reorder element with true if reorder field is not found, it will add field with a value specified
 //updates multiple documents

  1. updateMany(): updates multiple documents with matching query
db.products.updateMany(
      { qty: { $gt: 4 } }, 
      { $set: { "Review" : true } }
   );
   
 //$gt: greater than
  1. updateOne(): finds the first document that matches the filter and applies the specified update modifications.\
db.products.updateOne(
   { qty: { $lte: 10 } }, 
   { $set: { reorder: true } })
  1. deleteOne(): delete first matching document of query filter
db.products.deleteOne( { "_id" : ObjectId("563237a41a4d68582c2509da") } );
  1. deleteMany(): deletes all the documents matching query
db.products.deleteMany( { "item" : "pen", "qty" : { $lte :1 } } );

// delete all the pens where qty is less than or equal to 1

11.explain() : returns query panner info all methods

db.products.explain().find({"item":"pen","qty":"4"})

About

Crud Operations with provenDB (MongoDB+Blockchain)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%