#1 2018-11-14 20:58:53

deitysou
Member
Registered: 2018-11-10
Posts: 6

MongoDB $geoNear

Hi,

I'm currently exploring MongoDB and the $geoNear functionality.

For studies I've read this documentation: Find Restaurants with Geospatial Queries

When I try this statement on my MongoDB (using Compass) with the exported data from the tutorial above everything is fine.

{
  $geoNear:
    {
       near:{type:"Point",coordinates:[-73.99279,40.719296]},
       maxDistance: 100,
       distanceField: "dist.calculated",
       includeLocs: "dist.location",
       num: 5,
       spherical: true
    }
}

I also was able to retrieve thos data within my MVC Server.

But currently I'm not able to reconstruct this data structur with a defined TSQLRecord.

TMyLocation = class(TSQLRecord)
    FType: RawUTF8;
    FCoordinates: TList<Double>;
  published
    property Coordinates: TList<Double> read FCoordinates write FCoordinates;
    property &Type: RawUTF8 read FType write FType;
end;

TAccountGeo = class(TSQLRecord)
  private
    FUserID: TID;
    FLocation: TMyLocation;
  published
    property UserID: TID read FUserID write FUserID;
    property Location: TMyLocation read FLocation write FLocation;
end;

As seen in this image  data example from mongodb
my structure significantly divers -> my generated content

Thanks for you help.

Offline

#2 2018-11-15 13:28:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,243
Website

Re: MongoDB $geoNear

TList<> is not supported as published property of TSQLRecord.
Also I don't undestand why you are making one-to-one ORM relationship with MongoDB.

Just define a Localtion: variant field in your TAccountGeo class, and work with it.

Offline

#3 2018-11-15 17:34:21

deitysou
Member
Registered: 2018-11-10
Posts: 6

Re: MongoDB $geoNear

ab wrote:

TList<> is not supported as published property of TSQLRecord.

Okay.

ab wrote:

Also I don't undestand why you are making one-to-one ORM relationship with MongoDB.

Shoud I not do that? What is the best approach to work with MongoDB?
I new to the mORMot Framework and MongoDB.

ab wrote:

Just define a Localtion: variant field in your TAccountGeo class, and work with it.

Currently I'm using TDocVariant and define my fields. I'm also able to save my documents.

But when I try to update my document I'm struggling.
I can load my document with FindDoc() but I'm not able to update values.
I tried those examples from Direct MongoDB database access

var
  LDoc : Variant;
begin
  ...
  doc := Coll.FindDoc('{userid:?}',[userid]);

The result is a variant array in your examples you retrieved a document like this:

doc := Coll.FindDoc('{_id:?}',[5]);

And access values like:

doc.Name := 'New Name';

Which is not working for me, e.g. when I try to acces doc._id. hmm

Offline

Board footer

Powered by FluxBB