https://github.com/matttuttle/mongo-haxe-driver
A MongoDB driver for Haxe
https://github.com/matttuttle/mongo-haxe-driver
haxe mongodb-driver
Last synced: 3 months ago
JSON representation
A MongoDB driver for Haxe
- Host: GitHub
- URL: https://github.com/matttuttle/mongo-haxe-driver
- Owner: MattTuttle
- License: mit
- Created: 2012-03-13T20:17:30.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2017-03-01T17:28:34.000Z (almost 9 years ago)
- Last Synced: 2023-03-11T23:27:27.611Z (almost 3 years ago)
- Topics: haxe, mongodb-driver
- Language: Haxe
- Homepage:
- Size: 113 KB
- Stars: 59
- Watchers: 8
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: license.txt
Awesome Lists containing this project
README
[](https://travis-ci.org/MattTuttle/mongo-haxe-driver) [](license.txt) [](http://lib.haxe.org/p/mongodb)
MongoDB driver for Haxe
====================================
This is a database driver for MongoDB written in Haxe and available for all targets allowing a socket connection (neko/php/cpp).
Find all objects in a collection
------------------------------------
Finding rows in a relational database can be a daunting process. Thankfully with Mongo it's just like accessing a regular Haxe object instance.
```haxe
import org.mongodb.Mongo;
class Main
{
public static function main()
{
var mongo = new Mongo(); // connects to MongoDB
var posts = mongo.blog.posts; // get the "blog.posts" collection
// loops through all objects in "test.posts"
for (post in posts.find())
{
trace(post.title); // assumes that all posts have a title
}
}
}
```
Inserting and updating
------------------------------------
Inserting object in Mongo is just as simple as putting values in an Array. Just create an object and put it in the collection by calling insert(). Updating objects is just as simple except we need a way to find the original object so we pass a selector object first.
```haxe
import org.mongodb.Mongo;
class Main
{
public static function main()
{
var mongo = new Mongo(); // connects to MongoDB
var posts = mongo.blog.posts; // get the "blog.posts" collection
// creating a new post is as easy as making a new object
var post = {
title: 'My awesome post',
body: 'MongoDB is easy as pie'
};
posts.insert(post); // save the post in Mongo
post.body = 'Made some updates to my post';
posts.update({title: post.title}, post); // update the post
}
}
```
Driver Roadmap
------------------------------------
Here are the features planned for future versions.
* Replica sets
* Automatic reconnection