--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/70744806-8236-4fa2-9255-26108043933d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1652539a-4f1c-4073-be3c-d09866615eca%40googlegroups.com.
{ some_storage: [ 1, 1, 2, 1, 5, 2 ] }
$project : {
new_field: some_storage[$old_field]
}
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/922463a8-dd3c-43ed-9b12-af6dfc23289b%40googlegroups.com.
db.employee.drop();
db.employee.insert({'_id' : 1, 'name' : 'Bob', 'department_id' : 1});
db.employee.insert({'_id' : 2, 'name' : 'Ted', 'department_id' : 1});
db.employee.insert({'_id' : 3, 'name' : 'Joe', 'department_id' : 2});
db.employee.insert({'_id' : 4, 'name' : 'Abe', 'department_id' : 2});
db.department.drop();
db.department.insert({'_id' : 1, 'name' : 'Accounting', 'company_id' : 5});
db.department.insert({'_id' : 2, 'name' : 'Accounting', 'company_id' : 6});
db.company.drop();
db.company.insert({'_id' : 5, 'name' : 'Acme Company'});
db.company.insert({'_id' : 6, 'name' : 'Beta Company'});
var company_id_array = [5, 6];
db.employee.aggregate([
{$project: {'name' : '$name', 'company_id' : '$company_id_array[$department_id]' }}
]);
//would return
{ "_id" : 1, "name" : "Bob", "company_id" : 5 }
{ "_id" : 2, "name" : "Ted", "company_id" : 5 }
{ "_id" : 3, "name" : "Joe", "company_id" : 6 }
{ "_id" : 4, "name" : "Abe", "company_id" : 6 }
{$project: {'name' : '$name', 'company_id' : {$company_id_array : {$selectIndex : $department_id}}}
var company_id_array = [5, 6];
db.employee.aggregate([
{$project: {'name' : '$name', 'company_id' : {'$company_id_array' : {$selectIndex : '$department_id'}} }},
{$group: {'_id : '$company_id', 'count' : {'$sum' : 1}}}
]);
db.employee.aggregate([
{$project: {'name' : '$name',
'company_id' : {
'$let': {
vars: { 'company_id_array': [5,6], 'department_id': '$department_id' },
in: {'$$company_id_array : {$selectIndex : '$$department_id'}}
}}
}}
]);
$company_id_array = [{'_id' : 1, 'name' : 'Acme Company'}, {'_id' : 2, 'name' : 'Beta Company'}];
//example project
{$project: {'name' : '$name', 'company_id' : {$company_id_array : {$selectIndex : '$department_id.name'}}}}
On Friday, July 11, 2014 11:48:37 PM UTC-7, Asya Kamsky wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;...