[SERVER-213] Array.fetchRefs( colName ) ( WAS : db.col.findOne().val.fetchAll() for lists of DBRefs ) Created: 06/Aug/09  Updated: 12/Jul/16  Resolved: 05/Oct/09

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1.2

Type: New Feature Priority: Major - P3
Reporter: Phillip Oldham Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The shell provides a way to fetch a DBRef'd document into the current one. It would be very useful to be able to do this on a list/array value - each document in an array which looks like a DBRef is fetched into the current doc. An example to illustrate the concept:

> var other =

{ s : "other thing", n : 1}

;
> db.otherthings.save(other);
> db.otherthings.find();

{"_id" : "497dbcb36b27d59a708e89a4" , "s" : "other thing" , "n" : 1}

> var another =

{ s : "another thing", n : 2}

;
> db.otherthings.save(another);
> db.otherthings.find();

{"_id" : "4a7aabf13240ba3080db97dd" , "s" : "another thing" , "n" : 2}

> var mongo = db.things.findOne();
> print(tojson(mongo));
{"_id" : "497dab624ee47b3a675d2d9c" , "name" : "mongo" , "type" : "database" , "data" : {"a" : 1 , "b" : 2}}
> mongo.otherthings = [new DBRef( 'otherthings' , other._id ), new DBRef( 'otherthings' , another._id )];

{"s" : "other thing" , "n" : 1 , "_id" : "497dbcb36b27d59a708e89a4"}

> db.things.save(mongo);
> db.things.findOne().otherthings.fetchAll();
{"_id" : "497dab624ee47b3a675d2d9c" , "name" : "mongo" , "type" : "database" , "data" :

{"a" : 1 , "b" : 2}

, "otherthings" : [

{"_id" : "497dbcb36b27d59a708e89a4" , "s" : "other thing" , "n" : 1}

,

{"_id" : "4a7aabf13240ba3080db97dd" , "s" : "another thing" , "n" : 2}

] }



 Comments   
Comment by Eliot Horowitz (Inactive) [ 16/Oct/09 ]

release 10/16/2009

Comment by Eliot Horowitz (Inactive) [ 17/Aug/09 ]

I'm thinking it would stay as fetch()
its fundamentally different since the method on an array will be on any array - so might be confusing otherwise.
could make fetchRef and fetch work on a regular dbref though

Comment by Phillip Oldham [ 17/Aug/09 ]

"maybe we should add a _ns field to the objects to se know which collection they came from"

Sounds good.

Will there be a corresponding .fetchRef() then, for singular DBRef instances? Or will this stay as .fetch()?

Comment by Eliot Horowitz (Inactive) [ 17/Aug/09 ]

Going to add a method to Array

fetchRefs( collectionName )

  • collectionName is optional
    if specified, only return refs to that collection, otherwise return objects from all

maybe we should add a _ns field to the objects to se know which collection they came from...

Comment by Phillip Oldham [ 17/Aug/09 ]

Sounds ok. The reason I mentioned replacing the array items is that if it's a mixed array it would make more sense, but as long as it can recognise the DBRefs in the array and collect those documents that should be fine. However, if the DBRefs link to documents in different collections, how would one know which collection a doc came from in the returned results?

Comment by Eliot Horowitz (Inactive) [ 16/Aug/09 ]

How would you feel about fetchAll() returning a list rather than replacing the list?

Generated at Thu Feb 08 02:53:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.