protected QueryMessage generateQueryMessage() { Document qdoc = new Document(); qdoc.Add("listDatabases", 1.0); //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); qmsg.NumberToReturn = -1; return qmsg; }
public void TestSendQueryMessage() { //Connection conn = new Connection("10.141.153.2"); Connection conn = new Connection(); conn.Open(); BsonDocument qdoc = new BsonDocument(); qdoc.Add("listDatabases", new BsonNumber(1.0)); //QueryMessage qmsg = new QueryMessage(qdoc,"system.namespaces"); QueryMessage qmsg = new QueryMessage(qdoc,"admin.$cmd"); qmsg.NumberToReturn = -1; conn.SendTwoWayMessage(qmsg); conn.Close(); }
public Cursor(Connection conn, String fullCollectionName, Document spec, int limit, int skip, Document fields) { _QueryMessage = new QueryMessage(); if (spec == null) spec = new Document(); _QueryMessage.FullCollectionName = fullCollectionName; _QueryMessage.NumberToReturn = limit; _QueryMessage.NumberToSkip = skip; this.connection = conn; this.fields = fields; this.spec = spec; _Special = false; _OrderBy = null; }
public void TestAllBytesWritten() { BsonDocument query = new BsonDocument(); query.Add("col1", BsonConvert.From(1)); QueryMessage msg = new QueryMessage(query,"TestDB.TestCol"); MemoryStream buffer = new MemoryStream(); msg.Write(buffer); Byte[] output = buffer.ToArray(); String hexdump = BitConverter.ToString(output); //Console.WriteLine("Dump: " + hexdump); Assert.IsTrue(output.Length > 0); Assert.AreEqual("3A-00-00-00-00-00-00-00-00-00-00-00-D4-07-00-00-00-00-00-00-54-65-73-74-44-42-2E-54-65-73-74-43-6F-6C-00-00-00-00-00-00-00-00-00-0F-00-00-00-10-63-6F-6C-31-00-01-00-00-00-00", hexdump); }
public void TestWriteMessageTwice() { string expectedHex = "3A-00-00-00-00-00-00-00-00-00-00-00-D4-07-00-00-00-00-00-00-54-65-73-74-44-42-2E-54-65-73-74-43-6F-6C-00-00-00-00-00-00-00-00-00-0F-00-00-00-10-63-6F-6C-31-00-01-00-00-00-00"; BsonDocument query = new BsonDocument(); query.Add("col1", BsonConvert.From(1)); QueryMessage msg = new QueryMessage(query,"TestDB.TestCol"); MemoryStream buffer = new MemoryStream(); msg.Write(buffer); Byte[] output = buffer.ToArray(); String hexdump = BitConverter.ToString(output); MemoryStream buffer2 = new MemoryStream(); msg.Write(buffer2); Byte[] output2 = buffer.ToArray(); String hexdump2 = BitConverter.ToString(output2); Assert.AreEqual(expectedHex,hexdump); Assert.AreEqual(hexdump,hexdump2); }
private void RetrieveData() { QueryMessage query = new QueryMessage(); query.FullCollectionName = this.FullCollectionName; query.Query = BsonConvert.From(this.Spec); query.NumberToReturn = this.Limit; query.NumberToSkip = this.Skip; if(this.Fields != null){ query.ReturnFieldSelector = BsonConvert.From(this.Fields); } try{ this.reply = connection.SendTwoWayMessage(query); this.id = this.reply.CursorID; if(this.Limit < 0)this.Limit = this.Limit * -1; }catch(IOException ioe){ throw new MongoCommException("Could not read data, communication failure", this.connection,ioe); } }