How to store Shapes in Mongo DB - mongodb

I want to create a database using mongoDb and I am new to this area. And also want to Insert and select data to store shapes like circle, triangle, etc. I want to know how to do it.

Assuming you are referring to storing shapes for geospatial queries, you can use the new support for GeoJSON objects in MongoDB 2.4 to store and query Point, LineString, and Polygon objects.
For more information see:
MongoDB 2.4 manual: Geospatial Indexes and Queries and Geospatial Query Compatibility Chart
The GeoJSON 1.0 spec

Related

Is it possible to retrieve the query mongodb compass uses when I visually modify a document?

I'm new to mongodb, and therefore it is still hard for me to create queries on my own. I found mongodb compass helpful to modify my documents, but would like to have queries in order to apply changes quicker to the production database.
Is there a way to modify a document visually using mongodb compass and then to get the query that mongodb compass uses behind the curtain?
If not, is there some different GUI application that could help me to create queries?

Filtering data from elastic search based on mongodb

I've a list of items in my ElasticSearch. User enters a query and I fetch the results from elastic search. Now, I've some user preferences stored in mongodb based on which I want to filter the results of elastic search.
Suppose, I get a list of items(item_ids) from Elasticsearch.
Mongo DB has following schema.
id, user_id, item_id
I choose this MongoDB schema because a user could have a very big list of items(in order of Millions), which he doesn't want to see in results.
How do I achieve this with scale? Do I need to change my schema?
You should use elasticsearch filtering for this, you can include the filter criteria in your ES query which would reduce the number of results to return without which
You have to return huge data set from ES and then do the filtering in MongoDB which is two step process and costly at both ES and mongo side.
With filters at ES, it would return less data which would avoid extra post-processing at mongoDB and filters are executed first and by default cached at elasticsearch side so you don't need further caching solution like redis etc.
Refer filter and query context and from same official doc, info about filter cache.
Frequently used filters will be cached automatically by Elasticsearch,
to speed up performance.

How can i combine $searchbeta and geo search in mongodb atlas

my team migrate data to mongodb atlas.
I have a question.
How can i combine $searchbeta and geo search in mongodb atlas.
The $search (or $searchBeta) stage now supports geospatial queries.
Your field that contains geospatial data must be mapped to geo type. Then there are a few possible ways to query that data: near, geoWithin and geoShape.

multi location document in mongo odm

since 1.9 mongo supports multi location documents http://www.mongodb.org/display/DOCS/Geospatial+Indexing#GeospatialIndexing-MultilocationDocuments
we are using doctrine mongo odm and this functionality is vital for our project.
does anybody know how to create a multi location document in mongo odm?
Cross-referencing this with the same question you asked in mongodb-odm issue.
I don't believe ODM needs any special support for this, just as it doesn't for multi-key indexing of array fields. Try defining a geo index on the field containing your array of points. Also, I'd note that ODM's geo documenation suggests using an embedded object to hold coordinates. MongoDB will support that, but an array (i.e. [x, y]) is preferred.

neo4j vs mongodb for spatial search

I'm getting ready to start a project where I will be building a recommendation engine for restaurants. I have been waffling between neo4j (graph db) and mongodb (document db). my nodes/documents will be things like restaurant and person. i know i will want some edges, something like person->likes->restaurant, or person->ate_at->restaurant. my main query, however, will be to find restaurants within X miles of location Y.
if i have 20 restaurant's within X miles of Y, but not connected by any edges, how will neo4j be able to handle the spatial query? i know with mongodb i can index on lat/long and query all restaurant types. does neo4j offer the same functionality in a disconnected graph?
when it comes to answering questions like, 'which restaurants do my friends eat at most often?', is neo4j (graph db) the way to go? or will mongodb (document db) provide me similar functionality?
Neo4j Spatial introduces a Spatial RTree (or other means) index that is part of the graph itself. That means, even disconnected domain entities will be found via the spatial search, if you index them (that is relationships will connect the Spatial index to the Restaurants). Also, this is flexible enough that you can combine the Raw BBox search in the RTree with other things like check on the restaurants categories in the same go, since you can hop out and in the different parts of the graph.
This way, neo4j Spatial is supporting the full range of search capabilities that you would expect form a full Topology, like combined searches and searches on polygons with holes etc.
Be aware that Neo4j Spatial is in 0.7, so be gentle and ask on http://groups.google.com/group/neo4j/about :)
I'm not that familiar with Neo4J Spatial but it would seem that MongoDB is at the very least a good fit since it's the database Foursquare uses with exactly the purpose you describe. MongoDB geo indexing is extremely fast and scales up nicely.
Another possible solution is to use CouchBase. It uses a document model as well - though you need to be much more comfortable with MapReduce for queries. It has better spatial capabilities right now thank MongoDB but that may change over time.
Suggestion aside, I agree that of the two choices you have given Mongo will suit your needs fine and probably more appropriate for your spatial queries.
Neo4j geospatial doesn't scale up that good. I created a geospatial layer in neo4j and added nodes to this layer. Beyond 10,000 nodes the addition of nodes to the layer becomes very slow even when using neo4j2.0
On the other hand, mongodb geo-location works comparatively much faster and is more scalable.