Apply for Zend Framework Certification Training

MongoDb






By default ,
if we perform any query on a mongodb collection it tends to return all the data
of a field in the matching document. So in order to avoid that we use projection.
Projections limit the fields returned by the query. The projection document can
specify the inclusion as well as exclusion of the fields as shows
below: { field-name-1 : value , field-name-2 : value, ..,.., so on}
here value can be either 1 or 0 where 1 signifies inclusion and 0 signifies exclusion.

     db.collection("company")
        .find({ position : "manager"})    
		.project({name:1 , email: 1})
        .toArray( (err , collection) => {
		 if(err) throw err;
		   console.log("Record foundsuccessfully");
		   console.log(collection);
		   db.close();
	 });

< First Getting Started With CodeIgniter URL Routing >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top