Find document but not by _id field [duplicate]









up vote
0
down vote

favorite













This question already has an answer here:



  • How to query nested objects?

    2 answers



  • MongoDB wildcard in the key of a query

    1 answer



  • How to find MongoDB field name at arbitrary depth

    2 answers



I have a small issue to find/select the document by field name but i don't need to find it by id, for example:



 
_id:ObjectId('1234567890'),
type:
cars:
models:
,
_id:ObjectId('12345678901'),
type:
boats:
models:




I need to select the document by "type.cars" and push into the "models" some data. The problem is that the id is not static and my be change in future, but the document structure will stay as it is "type.models". I tried to google for the solution but couldn't find anything, if you can give me an idea or a link where i can do my homework?



here is what i tried and it doesn't work for me:



findOneAndUpdate(type:'cars',$push: models:'volvo':true);


Thanks :)










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 at 1:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
    – Vadim Korolov
    Nov 12 at 1:10











  • db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
    – Vadim Korolov
    Nov 12 at 3:55















up vote
0
down vote

favorite













This question already has an answer here:



  • How to query nested objects?

    2 answers



  • MongoDB wildcard in the key of a query

    1 answer



  • How to find MongoDB field name at arbitrary depth

    2 answers



I have a small issue to find/select the document by field name but i don't need to find it by id, for example:



 
_id:ObjectId('1234567890'),
type:
cars:
models:
,
_id:ObjectId('12345678901'),
type:
boats:
models:




I need to select the document by "type.cars" and push into the "models" some data. The problem is that the id is not static and my be change in future, but the document structure will stay as it is "type.models". I tried to google for the solution but couldn't find anything, if you can give me an idea or a link where i can do my homework?



here is what i tried and it doesn't work for me:



findOneAndUpdate(type:'cars',$push: models:'volvo':true);


Thanks :)










share|improve this question













marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 at 1:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
    – Vadim Korolov
    Nov 12 at 1:10











  • db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
    – Vadim Korolov
    Nov 12 at 3:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • How to query nested objects?

    2 answers



  • MongoDB wildcard in the key of a query

    1 answer



  • How to find MongoDB field name at arbitrary depth

    2 answers



I have a small issue to find/select the document by field name but i don't need to find it by id, for example:



 
_id:ObjectId('1234567890'),
type:
cars:
models:
,
_id:ObjectId('12345678901'),
type:
boats:
models:




I need to select the document by "type.cars" and push into the "models" some data. The problem is that the id is not static and my be change in future, but the document structure will stay as it is "type.models". I tried to google for the solution but couldn't find anything, if you can give me an idea or a link where i can do my homework?



here is what i tried and it doesn't work for me:



findOneAndUpdate(type:'cars',$push: models:'volvo':true);


Thanks :)










share|improve this question














This question already has an answer here:



  • How to query nested objects?

    2 answers



  • MongoDB wildcard in the key of a query

    1 answer



  • How to find MongoDB field name at arbitrary depth

    2 answers



I have a small issue to find/select the document by field name but i don't need to find it by id, for example:



 
_id:ObjectId('1234567890'),
type:
cars:
models:
,
_id:ObjectId('12345678901'),
type:
boats:
models:




I need to select the document by "type.cars" and push into the "models" some data. The problem is that the id is not static and my be change in future, but the document structure will stay as it is "type.models". I tried to google for the solution but couldn't find anything, if you can give me an idea or a link where i can do my homework?



here is what i tried and it doesn't work for me:



findOneAndUpdate(type:'cars',$push: models:'volvo':true);


Thanks :)





This question already has an answer here:



  • How to query nested objects?

    2 answers



  • MongoDB wildcard in the key of a query

    1 answer



  • How to find MongoDB field name at arbitrary depth

    2 answers







mongodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 0:58









Vadim Korolov

10211




10211




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 at 1:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 12 at 1:00


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
    – Vadim Korolov
    Nov 12 at 1:10











  • db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
    – Vadim Korolov
    Nov 12 at 3:55

















  • I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
    – Vadim Korolov
    Nov 12 at 1:10











  • db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
    – Vadim Korolov
    Nov 12 at 3:55
















I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
– Vadim Korolov
Nov 12 at 1:10





I dont have the value to search by as shown in that answer. I need to select the 'type.cars' and push in to models the data. The answer is different the one i am looking for.
– Vadim Korolov
Nov 12 at 1:10













db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
– Vadim Korolov
Nov 12 at 3:55





db.find().forEach(function (doc) if(doc.cars) db.updateOne(_id:doc._id,$push:'cars.models':volvo:'xc90') )
– Vadim Korolov
Nov 12 at 3:55


















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto