An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![Build Status](https://img.shields.io/travis/MattTuttle/mongo-haxe-driver.svg?style=flat)](https://travis-ci.org/MattTuttle/mongo-haxe-driver) [![Haxelib]( https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](license.txt) [![Haxelib]( https://img.shields.io/github/tag/MattTuttle/mongo-haxe-driver.svg?style=flat&label=haxelib)](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