Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get specific part of document

Tags:

mongodb

I'm trying Mongo db and I wonder if it's possible to only get a specific part of a document?

For example I have:

{   "name" : "MongoDB",   "info" : { x : 203, y : 102 } } 

and I only want the content of info.

The closest I found is db.collection.find({}, { info: 1 }) but this returns me { "info" : { x : 203, y : 102 } } when I only need { x : 203, y : 102 }.

like image 440
powderkeg Avatar asked Mar 14 '11 17:03

powderkeg


People also ask

How do I extract part of a Word document?

Extract Pages From Word – EasyClick at the beginning of the page, hold the left mouse button down, and drag the cursor to the end of the page to highlight all the content you want. Then press Ctrl+C to copy the text or Ctrl+X to cut it out of the document.

How do I select a portion of a document?

To select lines, click on the left edge of the window, or press CTRL + F8. To select vertically (in a rectangular block), use the mouse to select while pressing the ALT key, or press SHIFT+ CTRL + F8.


1 Answers

You could do

db.collection.find({},{'info.x':1, 'info.y':1}) 

but that means listing each and every item of the info object in the projection - which may or may not be what you're looking for.

like image 147
Lucas Zamboulis Avatar answered Nov 12 '22 16:11

Lucas Zamboulis