Find document but not by _id field [duplicate]










0
















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 '18 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 '18 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 '18 at 3:55
















0
















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 '18 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 '18 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 '18 at 3:55














0












0








0









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 '18 at 0:58









Vadim KorolovVadim Korolov

10711




10711




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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 3:55













0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)