Giter Club home page Giter Club logo

tmongowire's Introduction

Delphi MongoDB Driver

A Delphi driver to access a mongoDB server. It uses jsonDoc.pas to store JSON documents. IJSONDocument maps variables onto Delphi variables of type Variant, which resembles the loose typing of JavaScript. There are three main units and two main classes to enable access to a mongo DB server:

jsonDoc.pas

Declares IJSONDocument and related interfaces, and the JSON function to create instances, optionally populated with data. IJSONDocument instances hold the data of a 'document', the basic unit of data mongoDB works with. A variable of type Variant can hold an interface reference to an instance, which enables embedding documents. Use Variant arrays (or IJSONArray) to store arrays of values in a document.

See also https://github.com/stijnsanders/jsonDoc#jsondoc

bsonTools.pas

Declares the LoadBSON and SaveBSON procedures.

Also declares the IBSONDocArray interface which can improve processing arrays of embedded documents by keeping a reference to the underlying data stream, and only loading one document at a time, possibly re-using allocated memory for the same keys if the documents have a similar structure. Attention: take care to keep the TStream instance in existance for as long as you're planning to use the linked IBSONDocArray instance. Failure to do so can lead to privileged instruction or access violation errors.

mongoWire.pas

Use an object of class TMongoWire to connection to a mongoDB server. It supports getting single items, performing inserts, updates and deletes.

Use objects of class TMongoWireQuery to query to a mongoDB server. It handles the cursor and subsequent requests to the server to get more data when needed.

mongoID.pas

Use function mongoObjectId to construct a new MongoDB-style id value.

mongoAuth3.pas

Use procedure MongoWireAuthenticate to authenticate a newly connected TMongoWire instance. As of version 3.0 MongoDB uses a slightly modified SCRAM-SHA-1 to vastly improve security with access control. (Use mongoAuth.pas for MongoDB versions prior to 3.0.)

mongoStream.pas

Use TMongoStream to load and store files in MongoDB. Internally .files and .chunks collections are used to store the data.

examples

See the example projects for straight-forward demonstration applications that use TMongoWire.

tmongowire's People

Contributors

johnidm avatar smokingdev avatar stijnsanders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmongowire's Issues

Compatibility xe6

Hi,

I have to use TMongoWire with Delphi XE6, but occurred error "[dcc32 Fatal Error] mongoWire.pas(5): F1026 File not found: 'C:\Users\johni\Downloads\MongoDBDelphiTMongoWire-master\prj\Sockets.dcu'"

The lib Sockets it not exists in Delphi XE6.

I can to change TTcpClient to TSocketClient.

Connect mongolab.com

Dear @stijnsanders, I want to connect in database registered in mongolab.com.

I tried FMongoWire.Open('ds043971.mongolab.com', 43971);, but return error 'MongoWire.Query: not authorized for query on delphi.items'

After, I tried FMongoWire.Open('mongodb://delphi:[email protected]:43971/delphi', 43971) return error 'The requested name is valid, but no data of the requested type was found'

Information of connection

To connect using the shell:
mongo ds043971.mongolab.com:43971/delphi -u -p
To connect using a driver via the standard URI (what's this?):
mongodb://:@ds043971.mongolab.com:43971/delphi

dbuser is delphi
dbpassword is delphi

I change db "mwx1" to "delphi" in MongoLab

It is possible to connect the MongoLab with TMongoWire?

Thanks.

ERROR - Download With Java driver

Hi
When uploading XML files with TMongoWire, then download with JAVA, XML returns corrupted with null character.

Detail, TMongoWire with TMongoWire works normally.

Images example.

erro02
erro01
)

$and operator query

Hi,
I wonder if you could possibly provide me an example of using the $and operator in a query?
I am looking for something like:
d := BSON(['customer.custNo',4000,$and[BSON(['allocated',TRUE]))])
Tried a few ways but just can't get it to work.
Thanks for all your previous help.

mLab Authenticate

Hello, I am Brazilian and we are developing a suite of components for MongoDB here in Brazil, based on the TMongoWire class, we are implementing the connection with mLab, but we are not having success in MongoDB version 3.2 authentication, could you help us with this? Below the link of the free suite that we are developing

Https://github.com/bittencourtthulio/TMongoComponents

Images lose quality when saving the TMongoWire.

hi
I have a problem when I upload large files such as videos.
They are losing quality.

So I changed the value of the const 'mongoStreamDefaultChunkSize' for $ E4E1C0, which is equal to 15000000 in decimal. With that the video did not lose more quality.

Same problem happens with images, if I leave the default value of const 'mongoStreamDefaultChunkSize'.

In my view this is not correct because the database is very large. Any suggestion?

Design of BSondoc is flawed as each element is a variant and not explicitly typed

When I have a JSON query to send to Mongo using MongoWire and the query is {field: "guid"} where guid is a string representation of a guid, the BSON objects are storing internally in the fElements array. That array holds the value as an OleVariant. So, when it goes to serialize over the wire, the code is looking at the string in Value and seeing that it looks like a GUID. So, it then serializes as binary data with a UUID subtype code (0x03). Problem is, that Mongo doesn't have UUID data in that field, but rather a string. It just so happenes to hold a string representation of a GUID, but the data is not a UUID. Instead of being implicit and trying to "automatically" recognized strings that are formatted as UUIDs and convert them to UUIDs, the fElements array should include an explicit type for each element. Then, we could use UUIDs when we want to and we could use strings when we want to without fear of "automatic" conversion that causes problems.

FElements:array of record
SortIndex,LoadIndex:integer;
Key:WideString;
Value:OleVariant;
end;

Delphi XE Error

Hello.
Delphi XE, mwx1 example:
I get an error on creating New record:
Unsupported variant type 0102 "id"

File corrupted when using TMongoStream

Hi Sanders,

I have the following situation:
Upload files in php and downlod in your component, when I do that the file is corrupted.
But when I upload and downlod for its component works correctly.

Any suggestions?

How to authenticate to a collection on Mongolab?

Trying to connect to MongoLab works fine.

Following authentification fails: (accounts is a collection within a database).

MongoWireAuthenticate(mdb,'accounts',usernameonMongoLab,pwd);

also tried a user from the database --> fails as well.

Mongoshell can connect fine with % mongo acct.mongolab.com:33037/database -u -p

Any idea on how to set this up in TMongoWire?

Number To Return

Would it be possible to show an example with the NumberToReturn property? I don't seem to be able to get it to work.
When I set WireQuery.NumberToReturn := 2;
It seems to make no difference.

[wish] Insert Update and Delete should be functions

The result of the RunCommand fc which is used to implement Insert, Update and Delete contains useful information (like the number of modified documents, etc), but is currently discarded. That information could be made available to the user, making Insert Update and Delete into functions which return the result of the call to RunCommand. (edit: contains -> returns) (edit: undone, the original was ok).

Run Javascript

Hi I do not seem to be able to get your javascript example to work.
Wire.Insert('system.js',BSON(['_id','x1','value',bsonJavaScriptCodePrefix+
'function(){return {test:123};}']));
d:=Wire.Get('$cmd',BSON(['eval','x1();']));
Memo1.Text:=BsonToJson(IUnknown(d['retval']) as IBSONDocument);
The error I am getting is: Could not convert variant of type (Null) into type (Unknown)

create record

Hello.
I can't understand how to create array of Objects in the created object.
This code does not work โ€” create simple array.
d:=BSON([
'_id', 111,
'data',VarArrayOf(['[','f1',11,']','[','f2',22,']']),
]);

With best regards,
Dmitry.

TMongoWire sorting a collection

I am new to mongodb and I am trying out TMongoWire with Delphi. Does anyone know how to sort a collection by field using TMongoWire? Such as by 'name'? Also how would I find all surnames beginning with say 'Da'?

Could not connect (authenticate) to cloud server (MongoDB 3.0 server) using MongoAuth or MongoAuth3

Hi There!

I tried to connect and authenticate to a cloud server (MongoDB 3.0), but I always get the same error with MongoAuth or MongoAuth3 units

The error is 'MongoWire: failed to authenticate as username'

I managed to connect to localhost and to another cloudserver (MongoDB 2.69) MongoLab with no problems, but to apollo.modulusmongo.net I could not.

Can you help me? Or give me any hint of what I doing wrong?

procedure TForm1.Button1Click(Sender: TObject);
var
db:TMongoWire;

q:TMongoWireQuery;
d:IBSONDocument;
wsUser, wsDatabase, wsPassword: WideString;
begin
wsDatabase := 'y3gabubO';
db := TMongoWire.Create(wsDatabase);
db.Open('apollo.modulusmongo.net');//port 27017 default
wsUser := 'uteknikao';
wsPassword := 'ptek#@ni@#kao';

MongoWireAuthenticate(db,wsUser, wsPassword);

d:=BSON;
q:=TMongoWireQuery.Create(db);
try
q.Query('descriptionStationSensors' , nil);
while q.Next(d) do
ShowMessage(VarToStr(d['id']));

finally
q.Free;
end;
end;

Run aggregate command

I have tried to do this but to no avail!
Could you give me an example of an 'aggregate' command please.
This is the command in mongochef:
db.invoice.aggregate(
// Pipeline
[
// Stage 1
{
$group: {
_id : "$customer.custNo",
company: {$addToSet: "$customer.company"},
balance: { $sum: { $subtract:["$grandTotal","$paid"] } },
count: { $sum: 1 }
}
},

]

);

Expression too complex

Hello!

Today I got the error "E2156 Expression too complex", does anyone know what I can do about this? I guess splitting the data inside JSON([]) up would be possible but I would like to keep it as a single entry.

Thanks,
Etienne

Linux Adaption

Hello,

I programmed an API using RAD Studio 10.4 including TMongoWire to connect to a MongoDB Server. Now I have the problem that this has to work on a Linux server. Is it possible to adapt it?

Thanks

Implement Search

Hello,

I am programming a search function into my application. I already have two different ways implemented and would be interested to know if you or anyone has implemented a method yourself/himself.
It has to be able to find parts of names, e.g. if I search for "Man" it has to output any document which holds the name "Manuel" or any other name with "Man".

I am happy for any information.

Thanks,
Etienne

[POSSIBLE PATCH] Delphi XE8 support

Hello,

Is there any plan to make it compatible with Delphi XE 8? I tried to use that, but the bsonDoc unit doesn't compile on this compiler.

Thank you!

Displaying values from embedded document

If I have a e.g a collection of 'orders' (orderno, date, ordertotal etc.) I know I can access an element of that order by using it's key name. e.g 'orderno'.
But if I have embedded within the orders 'items' (itemid, qty, description etc.), how do I display these values?
I have tried - (with d as my returned IBSONDocument)
Memo.Lines.Add(VarToStr(d['items.description']));
but I get an empty string.

Access Violation XE6

Just trying the latest JSON version of TMongoWire using example1 in XE6.
Everytime I try to insert a document I get an access violation. The problem seems to
lie in bsonTools.pas - (stack[stackIndex].e:=e;).
Hope this helps.

Demo mwx2 does not delete properly

Not sure if this is the right place to make this comment but the 2nd demo does not remove the chunks. Therefore I modified the function inside mwx2Main to:

procedure TForm1.btnDeleteClick(Sender: TObject);
var
li:TListItem;
begin
li:=ListView1.Selected;
if li<>nil then
if MessageBox(Handle,PChar('Are you sure to delete "'+li.Caption+'"?'),
'mwx2',MB_OKCANCEL or MB_ICONQUESTION)=idOK then
begin
FDB.Delete(FilesCollection+'.files',BSON(['_id',li.SubItems[siID]]));
FDB.Delete(FilesCollection+'.chunks',BSON(['files_id',li.SubItems[siID]])); //Added
li.Delete;
end;
end;

This seems to do the trick

How execute mongodb function (JavaScript) from Delphi

i write in mongo.exe console any function :

var func1=function (str) {return db.Stats.find({idPl:{$in:db.Players.distinct('_id',{PN: str})}})}

How call this function from Delphi

FMongoWire.Get('mongodb_test.func1(/qwe/)', nil); //Not work !

add object to array

Hello.
Help, please, I can't to find the solution.

There is the object
{
"_id" : "id1",
"data" : [
{
"jobs" : [
{
"title" : "t1",
"type" : "tt1",
"category" : "c1"
},
{
"title" : "t2",
"type" : "tt2",
"category" : "c2"
}
]
}
]
}
I want to add the third job to the jobs array.
doc:=FMongoWire.Get(mwCollectionPersons,dSelector);
d0:= JSON(doc['data'][0]);
jobs_ru:= d0['jobs'];
n:= VarArrayHighBound(jobs_ru,1)+1;
VarArrayRedim(jobs_ru, n+1);
jobs_ru[n]:=JSON(['title','t3','type','tt3']);

fMongoWire.Update(mwCollectionPersons,dSelector,doc);
I have found that this code does not increase length of jobs array:

Could you posible to help me?
With best regards,
Dmitry.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.