Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 95 lines (87 sloc) 3.868 kb
160c21c @gerald-lindsly Mongo class complete
authored
1 classdef MongoCursor < handle
f518696 @gerald-lindsly Docs done
authored
2 % MongoCursor - Used to step through matching documents.
3 % Example:
4 % % Display alphabetically names of people age 18.
5 % bb = BsonBuffer;
6 % bb.append('age', int32(18));
7 % query = bb.finish();
8 % cursor = MongoCursor(query);
9 % bb = BsonBuffer;
10 % bb.append('name', true);
11 % cursor.sort = bb.finish();
12 % if mongo.find('test.people', cursor)
13 % while cursor.next()
14 % b = cursor.value();
15 % disp(b.value('name'));
16 % end
17 % clear cursor
18 % end
637a3f5 @gerald-lindsly Making progress
authored
19 properties
f518696 @gerald-lindsly Docs done
authored
20 h % lib.pointer to external data
21 query % The query to match against
22 sort % Any sort to be applied to the results
23 fields % bson object describing a subset of fields to be returned
92ab7e6 @gerald-lindsly GridFS implemented
authored
24 mongo % hold a reference to prevent release %
f518696 @gerald-lindsly Docs done
authored
25 limit = int32(0) % Number of documents to return. 0 default = all.
26 skip = int32(0) % Number of documents to skip
27 options = uint32(0) % Options to be applied to the search
637a3f5 @gerald-lindsly Making progress
authored
28 end
29
92ab7e6 @gerald-lindsly GridFS implemented
authored
30 properties (Constant)
b9fca3c @gerald-lindsly typo fix
authored
31 % Options:
92ab7e6 @gerald-lindsly GridFS implemented
authored
32 tailable = uint32(2); % Create a tailable cursor. %
33 slave_ok = uint32(4); %*< Allow queries on a non-primary node. %
34 no_timeout = uint32(16); %*< Disable cursor timeouts. %
35 await_data = uint32(32); %*< Momentarily block for more data. %
36 exhaust = uint32(64); %*< Stream in multiple 'more' packages. %
37 partial = uint32(128); %*< Allow reads even if a shard is down. %
38 end
39
637a3f5 @gerald-lindsly Making progress
authored
40 methods
160c21c @gerald-lindsly Mongo class complete
authored
41 function cursor = MongoCursor(varargin)
f518696 @gerald-lindsly Docs done
authored
42 % cursor = MongoCursor() Construct a cursor with an empty query
43 % which will match all documents in a collection.
44 % cursor = MongoCursor(query) Construct a cursor and
45 % initialize the query (Bson object) property to that given.
46 % Manually initialize the other properties yourself before
47 % calling mongo.find().
160c21c @gerald-lindsly Mongo class complete
authored
48 cursor.h = libpointer('mongo_cursor_Ptr');
637a3f5 @gerald-lindsly Making progress
authored
49 if nargin > 1
f518696 @gerald-lindsly Docs done
authored
50 error('MongoCursor:MongoCursor', 'Too many arguments');
637a3f5 @gerald-lindsly Making progress
authored
51 elseif nargin == 1
160c21c @gerald-lindsly Mongo class complete
authored
52 cursor.query = varargin{1};
637a3f5 @gerald-lindsly Making progress
authored
53 end
54 end
55
56 function more = next(cursor)
f518696 @gerald-lindsly Docs done
authored
57 % more = cursor.next() Advance to the next record of the result set.
58 % Returns logical 1 if there was another document; otherwise, 0.
637a3f5 @gerald-lindsly Making progress
authored
59 more = (calllib('MongoMatlabDriver', 'mmongo_cursor_next', cursor.h) ~= 0);
60 end
61
62 function v = value(cursor)
f518696 @gerald-lindsly Docs done
authored
63 % v = cursor.value() Return the current document of the result set.
637a3f5 @gerald-lindsly Making progress
authored
64 v = Bson;
65 if ~calllib('MongoMatlabDriver', 'mongo_cursor_value', cursor.h, v.h)
66 v = [];
67 end
68 end
69
160c21c @gerald-lindsly Mongo class complete
authored
70 function delete(cursor)
f518696 @gerald-lindsly Docs done
authored
71 % Release this cursor. MongoCursor objects should be cleared after use so
72 % that resources attached to the cursor may be released on both the client
73 % and server ends.
637a3f5 @gerald-lindsly Making progress
authored
74 if ~isNull(cursor.h)
160c21c @gerald-lindsly Mongo class complete
authored
75 calllib('MongoMatlabDriver', 'mongo_cursor_free', cursor.h);
637a3f5 @gerald-lindsly Making progress
authored
76 end
77 end
78
79 end
80 end
c95a15a @gerald-lindsly Copyright moved to end of source so help works
authored
81
82 % Copyright 2009-2011 10gen Inc.
83 %
84 % Licensed under the Apache License, Version 2.0 (the "License");
85 % you may not use this file except in compliance with the License.
86 % You may obtain a copy of the License at
87 %
88 % http://www.apache.org/licenses/LICENSE-2.0
89 %
90 % Unless required by applicable law or agreed to in writing, software
91 % distributed under the License is distributed on an "AS IS" BASIS,
92 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93 % See the License for the specific language governing permissions and
94 % limitations under the License.
Something went wrong with that request. Please try again.