Permalink
Browse files

Driver Sync

  • Loading branch information...
1 parent 2f9f6be commit a8f029ce2056602fadb489cf32c5fb07b946ae0b @gerald-lindsly committed Mar 5, 2012
View
@@ -0,0 +1 @@
+PKG_CFLAGS+=-D_MONGO_USE_GETADDRINFO
View
@@ -0,0 +1,4 @@
+R CMD INSTALL rmongodb
+if not errorlevel 1 goto Done
+echo ERROR
+:Done
View
@@ -1,3 +1,6 @@
rd /s/q rmongodb\src-i386
rd /s/q rmongodb\src-x64
R CMD check rmongodb
+if not errorlevel 1 goto Done
+echo ERROR
+:Done
View
Binary file not shown.
View
@@ -1,8 +1,8 @@
Package: rmongodb
Type: Package
Title: R-MongoDB driver
-Version: 1.0.2
-Date: 2011-11-25
+Version: 1.0.3
+Date: 2012-3-5
Author: Gerald Lindsly & 10gen, Inc. (mongo-c-driver)
Maintainer: Gerald Lindsly <gerald.lindsly@gmail.com>
Description: Provides an interface to MongoDB for R
View
@@ -52,6 +52,7 @@ export(mongo.index.sparse)
export(mongo.index.create)
export(mongo.count)
export(mongo.command)
+export(mongo.distinct)
export(mongo.simple.command)
export(mongo.drop.database)
export(mongo.drop)
View
@@ -182,3 +182,16 @@ mongo.get.databases <- function(mongo)
mongo.get.database.collections <- function(mongo, db)
.Call(".mongo.get.database.collections", mongo, db)
+mongo.distinct <- function(mongo, ns, key) {
+ pos <- regexpr('\\.', ns)
+ if (pos == 0) {
+ print("mongo.distict: No '.' in namespace")
+ return(NULL)
+ }
+ db <- substr(ns, 1, pos-1)
+ collection <- substr(ns, pos+1, nchar(ns))
+ b <- mongo.command(mongo, db, list(distinct=collection, key=key))
+ if (!is.null(b))
+ b <- mongo.bson.value(b, "values")
+ b
+}
@@ -0,0 +1,35 @@
+% File rmongodb/man/mongo.distinct.Rd
+\name{mongo.distinct}
+\alias{mongo.distinct}
+\title{Get a vector of distinct keys in a collection}
+\description{
+Get a vector of distinct keys in a collection.
+
+See \url{http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Distinct}.
+}
+\usage{
+mongo.distinct(mongo, ns, key)
+}
+\arguments{
+\item{mongo}{(\link{mongo}) A mongo connection object.}
+\item{ns}{(string) The namespace of the collection in which to find distinct keys.}
+\item{key}{(string) The name of the key field for which to get distinct values.}
+}
+\value{
+NULL if the command failed. \code{\link{mongo.get.err}()} may be MONGO_COMMAND_FAILED.
+
+(vector) The result set of distinct keys.
+}
+\examples{
+mongo <- mongo.create()
+if (mongo.is.connected(mongo)) {
+ keys <- mongo.distinct(mongo, "test.people", "name")
+ print(keys)
+}
+}
+\seealso{
+\code{\link{mongo.command}},\cr
+\code{\link{mongo.simple.command}},\cr
+\code{\link{mongo.find}},\cr
+\link{mongo}.
+}
@@ -12,8 +12,8 @@ Provides an interface to MongoDB for R
\tabular{ll}{
Package: \tab rmongodb\cr
Type: \tab Package\cr
-Version: \tab 1.0.2\cr
-Date: \tab 2011-11-25\cr
+Version: \tab 1.0.3\cr
+Date: \tab 2012-3-5\cr
License: \tab Apache 2\cr
LazyLoad: \tab yes\cr
}
View
@@ -20,19 +20,18 @@
#include "api_mongo.h"
#include "api_gridfs.h"
#include "symbols.h"
-
-int sock_init();
+#include "net.h"
static const R_CallMethodDef callMethods[] = {
- { ".mongo.create", (DL_FUNC) mongo_create, 0 },
+ { ".mongo.create", (DL_FUNC) mmongo_create, 0 },
{ ".mongo.connect", (DL_FUNC) rmongo_connect, 1 },
- { ".mongo.is.connected", (DL_FUNC) mongo_is_connected, 1 },
- { ".mongo.get.err", (DL_FUNC) mongo_get_err, 1 },
+ { ".mongo.is.connected", (DL_FUNC) mmongo_is_connected, 1 },
+ { ".mongo.get.err", (DL_FUNC) mmongo_get_err, 1 },
{ ".mongo.reconnect", (DL_FUNC) rmongo_reconnect, 1 },
{ ".mongo.disconnect", (DL_FUNC) rmongo_disconnect, 1 },
{ ".mongo.destroy", (DL_FUNC) rmongo_destroy, 1 },
- { ".mongo.get.socket", (DL_FUNC) mongo_get_socket, 1 },
- { ".mongo.get.primary", (DL_FUNC) mongo_get_primary, 1 },
+ { ".mongo.get.socket", (DL_FUNC) mmongo_get_socket, 1 },
+ { ".mongo.get.primary", (DL_FUNC) mmongo_get_primary, 1 },
{ ".mongo.get.hosts", (DL_FUNC) mongo_get_hosts, 1 },
{ ".mongo.set.timeout", (DL_FUNC) mongo_set_timeout, 2 },
{ ".mongo.get.timeout", (DL_FUNC) mongo_get_timeout, 1 },
@@ -42,8 +41,8 @@ static const R_CallMethodDef callMethods[] = {
{ ".mongo.is.master", (DL_FUNC) mongo_is_master, 1 },
{ ".mongo.add.user", (DL_FUNC) mongo_add_user, 4 },
{ ".mongo.authenticate", (DL_FUNC) mongo_authenticate, 4 },
- { ".mongo.get.server.err", (DL_FUNC) mongo_get_server_err, 1 },
- { ".mongo.get.server.err.string", (DL_FUNC) mongo_get_server_err_string, 1 },
+ { ".mongo.get.server.err", (DL_FUNC) mmongo_get_server_err, 1 },
+ { ".mongo.get.server.err.string", (DL_FUNC) mmongo_get_server_err_string, 1 },
{ ".mongo.insert", (DL_FUNC) rmongo_insert, 3 },
{ ".mongo.insert.batch", (DL_FUNC) rmongo_insert_batch, 3 },
{ ".mongo.update", (DL_FUNC) rmongo_update, 5 },
@@ -169,7 +168,7 @@ static void _err_handler(const char* errmsg) {
void attribute_visible R_init_rmongodb(DllInfo *dll) {
R_registerRoutines(dll, NULL, callMethods, NULL, NULL);
- sock_init();
+ mongo_sock_init();
install_mongo_symbols();
bson_malloc_func = _malloc;
bson_realloc_func = _realloc;
@@ -303,7 +303,8 @@ SEXP mongo_gridfile_get_descriptor(SEXP gfile) {
SEXP mongo_gridfile_get_metadata(SEXP gfile) {
gridfile* _gfile = _checkGridfile(gfile);
- bson meta = gridfile_get_metadata(_gfile);
+ bson meta;
+ gridfile_get_metadata(_gfile, &meta);
if (bson_size(&meta) <= 5)
return R_NilValue;
SEXP ret = _mongo_bson_create(&meta);
@@ -315,7 +316,8 @@ SEXP mongo_gridfile_get_metadata(SEXP gfile) {
SEXP mongo_gridfile_get_chunk(SEXP gfile, SEXP i) {
gridfile* _gfile = _checkGridfile(gfile);
int _i = asInteger(i);
- bson chunk = gridfile_get_chunk(_gfile, _i);
+ bson chunk;
+ gridfile_get_chunk(_gfile, _i, &chunk);
if (bson_size(&chunk) <= 5)
return R_NilValue;
SEXP ret = _mongo_bson_create(&chunk);
View
@@ -34,7 +34,7 @@ SEXP rmongo_destroy(SEXP mongo_conn) {
}
-SEXP mongo_create() {
+SEXP mmongo_create() {
SEXP ret, ptr, cls;
PROTECT(ret = allocVector(INTSXP, 1));
INTEGER(ret)[0] = 0;
@@ -118,7 +118,7 @@ SEXP rmongo_disconnect(SEXP mongo_conn) {
}
-SEXP mongo_get_socket(SEXP mongo_conn) {
+SEXP mmongo_get_socket(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(INTSXP, 1));
@@ -128,7 +128,7 @@ SEXP mongo_get_socket(SEXP mongo_conn) {
}
-SEXP mongo_is_connected(SEXP mongo_conn) {
+SEXP mmongo_is_connected(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(LGLSXP, 1));
@@ -138,7 +138,7 @@ SEXP mongo_is_connected(SEXP mongo_conn) {
}
-SEXP mongo_get_err(SEXP mongo_conn) {
+SEXP mmongo_get_err(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(INTSXP, 1));
@@ -148,7 +148,7 @@ SEXP mongo_get_err(SEXP mongo_conn) {
}
-SEXP mongo_get_server_err(SEXP mongo_conn) {
+SEXP mmongo_get_server_err(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(INTSXP, 1));
@@ -158,7 +158,7 @@ SEXP mongo_get_server_err(SEXP mongo_conn) {
}
-SEXP mongo_get_server_err_string(SEXP mongo_conn) {
+SEXP mmongo_get_server_err_string(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(STRSXP, 1));
@@ -532,18 +532,18 @@ SEXP mongo_authenticate(SEXP mongo_conn, SEXP user, SEXP pass, SEXP db) {
}
-const char* _get_host_port(mongo_host_port* hp) {
+const char* get_host_port_(mongo_host_port* hp) {
static char _hp[sizeof(hp->host)+12];
sprintf(_hp, "%s:%d", hp->host, hp->port);
return _hp;
}
-SEXP mongo_get_primary(SEXP mongo_conn) {
+SEXP mmongo_get_primary(SEXP mongo_conn) {
mongo* conn = _checkMongo(mongo_conn);
SEXP ret;
PROTECT(ret = allocVector(STRSXP, 1));
- SET_STRING_ELT(ret, 0, mkChar(_get_host_port(conn->primary)));
+ SET_STRING_ELT(ret, 0, mkChar(get_host_port_(conn->primary)));
UNPROTECT(1);
return ret;
}
@@ -561,7 +561,7 @@ SEXP mongo_get_hosts(SEXP mongo_conn) {
PROTECT(ret = allocVector(STRSXP, count));
int i = 0;
for (hp = r->hosts; hp; hp = hp->next, i++)
- SET_STRING_ELT(ret, i, mkChar(_get_host_port(hp)));
+ SET_STRING_ELT(ret, i, mkChar(get_host_port_(hp)));
UNPROTECT(1);
return ret;
}
View
@@ -14,21 +14,21 @@
*/
#include <Rinternals.h>
-SEXP mongo_create();
+SEXP mmongo_create();
SEXP rmongo_connect(SEXP mongo_conn);
SEXP rmongo_reconnect(SEXP mongo_conn);
SEXP rmongo_disconnect(SEXP mongo_conn);
SEXP rmongo_destroy(SEXP mongo_conn);
-SEXP mongo_is_connected(SEXP mongo_conn);
-SEXP mongo_get_socket(SEXP mongo_conn);
-SEXP mongo_get_primary(SEXP mongo_conn);
+SEXP mmongo_is_connected(SEXP mongo_conn);
+SEXP mmongo_get_socket(SEXP mongo_conn);
+SEXP mmongo_get_primary(SEXP mongo_conn);
SEXP mongo_get_hosts(SEXP mongo_conn);
-SEXP mongo_get_err(SEXP mongo_conn);
+SEXP mmongo_get_err(SEXP mongo_conn);
SEXP mongo_set_timeout(SEXP mongo_conn, SEXP timeout);
SEXP mongo_get_timeout(SEXP mongo_conn);
-SEXP mongo_get_server_err(SEXP mongo_conn);
-SEXP mongo_get_server_err_string(SEXP mongo_conn);
+SEXP mmongo_get_server_err(SEXP mongo_conn);
+SEXP mmongo_get_server_err_string(SEXP mongo_conn);
SEXP rmongo_insert(SEXP mongo_conn, SEXP ns, SEXP b);
SEXP rmongo_insert_batch(SEXP mongo_conn, SEXP ns, SEXP b);
@@ -1 +1,2 @@
-PKG_LIBS = -lws2_32
+PKG_LIBS = -lws2_32
+PKG_CFLAGS+=-DMONGO_STATIC_BUILD
Binary file not shown.
View
@@ -1,48 +0,0 @@
-/* Copyright (C) 2008-2011 10gen Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-#include <R.h>
-#include "net.h"
-#include "symbols.h"
-
-
-
-/* Initialize the socket services */
-int sock_init() {
- static int called_once;
- static int retval;
- if (called_once) return retval;
- called_once = 1;
-
-#if defined(_WIN32)
- WSADATA wsaData;
- WORD wVers = MAKEWORD(1, 1);
- return retval = (WSAStartup(wVers, &wsaData) == 0);
-#elif defined(MACINTOSH)
- GUSISetup(GUSIwithInternetSockets);
- return retval = 1;
-#elif defined(SIGPIPE)
- retval = 1;
- struct sigaction act;
- if (sigaction(SIGPIPE, (struct sigaction *)NULL, &act) < 0)
- retval = 0;
- else if (act.sa_handler == SIG_DFL) {
- act.sa_handler = SIG_IGN;
- if (sigaction(SIGPIPE, &act, (struct sigaction *)NULL) < 0)
- retval = 0;
- }
- return retval;
-#endif
-}
-
View
12 test.R
@@ -199,7 +199,7 @@ mongo.simple.command(mongo, db, "badcommand", 0L)
print(mongo.get.err(mongo))
print("insert")
-print(mongo.insert(mongo, ns, b))
+#print(mongo.insert(mongo, ns, b)) #
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append(buf, "name", "Dwight")
@@ -335,17 +335,17 @@ print(mongo.bson.to.list(b))
gfs <- mongo.gridfs.create(mongo, "grid")
if (!mongo.gridfs.store.file(gfs, "test.R"))
- error("unable to store test.R")
+ stop("unable to store test.R")
if (!mongo.gridfs.store.file(gfs, "rmongodb.pdf"))
- error("unable to store rmongodb.pdf")
+ stop("unable to store rmongodb.pdf")
if (!mongo.gridfs.store.file(gfs, "check.bat"))
- error("unable to store check.bat")
+ stop("unable to store check.bat")
if (!mongo.gridfs.store.file(gfs, "test.bat"))
- error("unable to store test.bat")
+ stop("unable to store test.bat")
mongo.gridfs.remove.file(gfs, "test.bat")
if (!is.null(mongo.gridfs.find(gfs, "test.bat")))
- error("mongo.gridfs.remove.file didn't work.")
+ stop("mongo.gridfs.remove.file didn't work.")
gridfile <- mongo.gridfs.find(gfs, "check.bat")
print(mongo.gridfile.get.descriptor(gridfile))

0 comments on commit a8f029c

Please sign in to comment.