Paste document without knowing _id in Mongoose / Mongodb

I know that there are no "unions" in MongoDB. I am trying to link a large number of documents with 40,000 places in my collection of places.

My place collection has user (read: not under my control) location identifiers and their corresponding lat / lng coordinates.

var Locations = new Schema({
    location_id: String, 
    loc: { //lng, lat: as per mongodb documents
         type: [Number], 
         index: '2d'
    } 
});

There are several collections that have a field that references this user identifier to match latitude and longitude.

var MyCollection = new Schema({
    location: String,
    otherFields: Strings...
});

I lost a little what is the best way to do this. Many posts offer a link through a Scheme, but I have only seen this with help Schema.Types.ObjectId. This seems impractical to me, because the data I import has only its own identifier.

MyCollection _id , . , - .

- ? .

JS, , . , .

+4
1

-, : MongoDb _id , .

1. "[...], if the mongod receives a document to insert that does not contain an _id field, mongod will add the _id field that holds an ObjectId. [...]" 

, location_id . location_id, ? , .

, location MyCollection location_id . , . location_id MyCollection , , MyCollection

Locations.find({location_id: <the_location_id>})

, , , ?

, MyCollection. , , , . 40.000 , , , 100? , .

lat, lon (Locations, MyCollection)? , , MyCollection (). MongoDb. , , MyCollection.

- :

Locations.find({lat: {$gt: <x>-a, $lt: <x>+a}, lon: {$gt: <y>-b, $lt: <y>+b}}, function(locations){ ... });

, .

+1

Source: https://habr.com/ru/post/1616799/


All Articles