Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- { "_id":1, "make":"Honda", "model":"Accord" },
- { "_id":2, "make":"Toyota", "model":"Camry" },
- { "_id":3, "make":"Honda", "model":"Civic" },
- { "_id":4, "make":"Subaru", "model":"Legacy" },
- { "_id":5, "make":"Subaru", "model":"Outback" },
- { "_id":6, "make":"Toyota", "model":"Corrola" }
- ]
- [
- { "description" : "Honda" },
- { "description" : "Honda - Accord" },
- { "description" : "Honda - Civic" },
- { "description" : "Subaru" },
- { "description" : "Subaru - Legacy" },
- { "description" : "Subaru - Outback" },
- { "description" : "Toyota" },
- { "description" : "Toyota - Camry" },
- { "description" : "Toyota - Corrola" }
- ]
- db.cars.aggregate([
- { $sort : { make : 1, model:1 } },
- { $project: {"_id":0, "description":{ $concat: [ "$make", " - ", "$model" ]} } }
- ])
- [
- { "description" : "Honda - Accord" },
- { "description" : "Honda - Civic" },
- { "description" : "Subaru - Legacy" },
- { "description" : "Subaru - Outback" },
- { "description" : "Toyota - Camry" },
- { "description" : "Toyota - Corrola" }
- ]
- db.cars.aggregate([
- { $sort: { make: 1, model: 1 }},
- { $group: {
- "_id": "$make",
- models: {
- $push: {
- $concat: ["$make", " - ", "$model"]
- }
- }
- }
- },
- { $project: {
- "_id": 0,
- "description": {
- $reduce: {
- input: "$models",
- initialValue: "$_id",
- in: {
- $concatArrays: ["$$value", "$$this"]
- }
- }
- }
- }
- }
- ])
- "errmsg" : "$concatArrays only supports arrays, not string",
- "code" : 28664,
Add Comment
Please, Sign In to add comment