I need to populate some array of indexes












1















I need to populate specific index of row in mongodb.



Here is my collection



{

"startTime": "00:00",
"endTime": "23:30",
"services": [
ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92"),
ObjectId("5b8f6273621c0f02a9ae30b9"),
ObjectId("5b90e33329d36e0014d2f6ff"),
ObjectId("5b8e6fd47365a5001413062e"),
ObjectId("5b8fb97b06d94a00143a11e7"),
ObjectId("5ba88de21aabd703443a411e"),
ObjectId("5b98e50ed6c3f80014d3c2cf"),
ObjectId("5b8e853f7365a500141308c1"),
ObjectId("5b9b7832d9f1070014352893"),
ObjectId("5bb1d6bf35c2de001301c99c")
],
"isActive": true,
"isDeleted": false,
}


I just need to populate these service ids ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92").










share|improve this question

























  • From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

    – Anthony Winzlet
    Nov 12 '18 at 12:43













  • I just need to populate these ids instead of all services.

    – ali ahmed
    Nov 12 '18 at 12:48
















1















I need to populate specific index of row in mongodb.



Here is my collection



{

"startTime": "00:00",
"endTime": "23:30",
"services": [
ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92"),
ObjectId("5b8f6273621c0f02a9ae30b9"),
ObjectId("5b90e33329d36e0014d2f6ff"),
ObjectId("5b8e6fd47365a5001413062e"),
ObjectId("5b8fb97b06d94a00143a11e7"),
ObjectId("5ba88de21aabd703443a411e"),
ObjectId("5b98e50ed6c3f80014d3c2cf"),
ObjectId("5b8e853f7365a500141308c1"),
ObjectId("5b9b7832d9f1070014352893"),
ObjectId("5bb1d6bf35c2de001301c99c")
],
"isActive": true,
"isDeleted": false,
}


I just need to populate these service ids ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92").










share|improve this question

























  • From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

    – Anthony Winzlet
    Nov 12 '18 at 12:43













  • I just need to populate these ids instead of all services.

    – ali ahmed
    Nov 12 '18 at 12:48














1












1








1








I need to populate specific index of row in mongodb.



Here is my collection



{

"startTime": "00:00",
"endTime": "23:30",
"services": [
ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92"),
ObjectId("5b8f6273621c0f02a9ae30b9"),
ObjectId("5b90e33329d36e0014d2f6ff"),
ObjectId("5b8e6fd47365a5001413062e"),
ObjectId("5b8fb97b06d94a00143a11e7"),
ObjectId("5ba88de21aabd703443a411e"),
ObjectId("5b98e50ed6c3f80014d3c2cf"),
ObjectId("5b8e853f7365a500141308c1"),
ObjectId("5b9b7832d9f1070014352893"),
ObjectId("5bb1d6bf35c2de001301c99c")
],
"isActive": true,
"isDeleted": false,
}


I just need to populate these service ids ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92").










share|improve this question
















I need to populate specific index of row in mongodb.



Here is my collection



{

"startTime": "00:00",
"endTime": "23:30",
"services": [
ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92"),
ObjectId("5b8f6273621c0f02a9ae30b9"),
ObjectId("5b90e33329d36e0014d2f6ff"),
ObjectId("5b8e6fd47365a5001413062e"),
ObjectId("5b8fb97b06d94a00143a11e7"),
ObjectId("5ba88de21aabd703443a411e"),
ObjectId("5b98e50ed6c3f80014d3c2cf"),
ObjectId("5b8e853f7365a500141308c1"),
ObjectId("5b9b7832d9f1070014352893"),
ObjectId("5bb1d6bf35c2de001301c99c")
],
"isActive": true,
"isDeleted": false,
}


I just need to populate these service ids ObjectId("5b90e29729d36e0014d2f6f2"),
ObjectId("5b8f96003b918f0014bb4b92").







mongodb mongoose mongodb-query aggregation-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 19:51









Anthony Winzlet

17.3k41845




17.3k41845










asked Nov 12 '18 at 12:30









ali ahmedali ahmed

449




449













  • From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

    – Anthony Winzlet
    Nov 12 '18 at 12:43













  • I just need to populate these ids instead of all services.

    – ali ahmed
    Nov 12 '18 at 12:48



















  • From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

    – Anthony Winzlet
    Nov 12 '18 at 12:43













  • I just need to populate these ids instead of all services.

    – ali ahmed
    Nov 12 '18 at 12:48

















From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

– Anthony Winzlet
Nov 12 '18 at 12:43







From where you are getting these ids ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")?

– Anthony Winzlet
Nov 12 '18 at 12:43















I just need to populate these ids instead of all services.

– ali ahmed
Nov 12 '18 at 12:48





I just need to populate these ids instead of all services.

– ali ahmed
Nov 12 '18 at 12:48












1 Answer
1






active

oldest

votes


















2














You can use $lookup aggregation in mongodb 3.6



var ids = [ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")]

db.collection.aggregate([
{ "$lookup": {
"from": "services",
"pipeline": [{ "$match": { "$expr": { "$in": ["$_id", ids ]}}}],
"as": "services"
}}
])





share|improve this answer
























  • Still it populates all services

    – ali ahmed
    Nov 12 '18 at 12:59











  • Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

    – Anthony Winzlet
    Nov 12 '18 at 13:03











  • why you add services as array of objects?

    – ali ahmed
    Nov 12 '18 at 13:06






  • 1





    Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

    – Anthony Winzlet
    Nov 12 '18 at 13:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262256%2fi-need-to-populate-some-array-of-indexes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can use $lookup aggregation in mongodb 3.6



var ids = [ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")]

db.collection.aggregate([
{ "$lookup": {
"from": "services",
"pipeline": [{ "$match": { "$expr": { "$in": ["$_id", ids ]}}}],
"as": "services"
}}
])





share|improve this answer
























  • Still it populates all services

    – ali ahmed
    Nov 12 '18 at 12:59











  • Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

    – Anthony Winzlet
    Nov 12 '18 at 13:03











  • why you add services as array of objects?

    – ali ahmed
    Nov 12 '18 at 13:06






  • 1





    Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

    – Anthony Winzlet
    Nov 12 '18 at 13:18
















2














You can use $lookup aggregation in mongodb 3.6



var ids = [ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")]

db.collection.aggregate([
{ "$lookup": {
"from": "services",
"pipeline": [{ "$match": { "$expr": { "$in": ["$_id", ids ]}}}],
"as": "services"
}}
])





share|improve this answer
























  • Still it populates all services

    – ali ahmed
    Nov 12 '18 at 12:59











  • Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

    – Anthony Winzlet
    Nov 12 '18 at 13:03











  • why you add services as array of objects?

    – ali ahmed
    Nov 12 '18 at 13:06






  • 1





    Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

    – Anthony Winzlet
    Nov 12 '18 at 13:18














2












2








2







You can use $lookup aggregation in mongodb 3.6



var ids = [ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")]

db.collection.aggregate([
{ "$lookup": {
"from": "services",
"pipeline": [{ "$match": { "$expr": { "$in": ["$_id", ids ]}}}],
"as": "services"
}}
])





share|improve this answer













You can use $lookup aggregation in mongodb 3.6



var ids = [ObjectId("5b90e29729d36e0014d2f6f2"), ObjectId("5b8f96003b918f0014bb4b92")]

db.collection.aggregate([
{ "$lookup": {
"from": "services",
"pipeline": [{ "$match": { "$expr": { "$in": ["$_id", ids ]}}}],
"as": "services"
}}
])






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 12:50









Anthony WinzletAnthony Winzlet

17.3k41845




17.3k41845













  • Still it populates all services

    – ali ahmed
    Nov 12 '18 at 12:59











  • Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

    – Anthony Winzlet
    Nov 12 '18 at 13:03











  • why you add services as array of objects?

    – ali ahmed
    Nov 12 '18 at 13:06






  • 1





    Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

    – Anthony Winzlet
    Nov 12 '18 at 13:18



















  • Still it populates all services

    – ali ahmed
    Nov 12 '18 at 12:59











  • Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

    – Anthony Winzlet
    Nov 12 '18 at 13:03











  • why you add services as array of objects?

    – ali ahmed
    Nov 12 '18 at 13:06






  • 1





    Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

    – Anthony Winzlet
    Nov 12 '18 at 13:18

















Still it populates all services

– ali ahmed
Nov 12 '18 at 12:59





Still it populates all services

– ali ahmed
Nov 12 '18 at 12:59













Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

– Anthony Winzlet
Nov 12 '18 at 13:03





Nopes it does work mongoplayground.net/p/d6ZdOo7lCoY

– Anthony Winzlet
Nov 12 '18 at 13:03













why you add services as array of objects?

– ali ahmed
Nov 12 '18 at 13:06





why you add services as array of objects?

– ali ahmed
Nov 12 '18 at 13:06




1




1





Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

– Anthony Winzlet
Nov 12 '18 at 13:18





Post your original collection in services array and check the reponse. here mongoplayground.net/p/_naL5KdppxX

– Anthony Winzlet
Nov 12 '18 at 13:18




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262256%2fi-need-to-populate-some-array-of-indexes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Lallio

Futebolista

Jornalista