Skip to content
This repository
Browse code

Add code that should query for girdfs files using arguments

  • Loading branch information...
commit b8e39be6d0817d63684b8e7a49ff6c22edb41519 1 parent db2547f
authored June 04, 2012

Showing 1 changed file with 12 additions and 8 deletions. Show diff stats Hide diff stats

  1. 20  mongo_gridfs.cpp
20  mongo_gridfs.cpp
@@ -98,19 +98,23 @@ static int gridfs_find_file(lua_State *L) {
98 98
 
99 99
 }
100 100
 
101  
-
102  
-
103  
-
104  
-
105 101
 /*
106  
- * cursor,err = gridfs:list()
  102
+ * cursor,err = gridfs:list([lua_table or json_str])
107 103
  */
108 104
 static int gridfs_list(lua_State *L) {
109 105
     GridFS *gridfs = userdata_to_gridfs(L, 1);
110 106
 
111  
-    auto_ptr<DBClientCursor> autocursor = gridfs->list();
  107
+    BSONObj query;
  108
+    int type = lua_type(L, 2);
  109
+    if (type == LUA_TSTRING) {
  110
+        const char *jsonstr = luaL_checkstring(L, 2);
  111
+        query = fromjson(jsonstr);
  112
+    } else if (type == LUA_TTABLE) {
  113
+        lua_to_bson(L, 2, query);
  114
+    }
  115
+    auto_ptr<DBClientCursor> autocursor = gridfs->list(query);
112 116
 
113  
-    if (!autocursor.get()) {
  117
+    if (!autocursor.get()){
114 118
         lua_pushnil(L);
115 119
         lua_pushstring(L, LUAMONGO_ERR_CONNECTION_LOST);
116 120
         return 2;
@@ -149,7 +153,7 @@ static int gridfs_remove_file(lua_State *L) {
149 153
 }
150 154
 
151 155
 /*
152  
- * gridfile, err = gridfs:store_file(filename[, remote_file], content_type]])
  156
+ * gridfile, err = gridfs:store_file(filename[, remote_file[, content_type]])
153 157
  */
154 158
 static int gridfs_store_file(lua_State *L) {
155 159
     int resultcount = 1;

0 notes on commit b8e39be

Please sign in to comment.
Something went wrong with that request. Please try again.