{"id":4422,"date":"2022-04-22T09:39:12","date_gmt":"2022-04-22T14:39:12","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=4422"},"modified":"2022-04-22T09:39:12","modified_gmt":"2022-04-22T14:39:12","slug":"searching-for-devices-in-unifi-via-command-line-mongodb","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/searching-for-devices-in-unifi-via-command-line-mongodb\/","title":{"rendered":"Searching for devices in UniFi via command line \/ MongoDB"},"content":{"rendered":"\n<p>While the UniFi controller is nice and everything, it does make it hard to see if a device is already adopted.  At least if you have a ton of sites.  Fortunately, we can search the database directly to find out if a UniFi is already adopted and which site it is assigned to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Connect to Mongo DB<\/h2>\n\n\n\n<p>First we need to connect to MongoDB.  And then we need to use the ace database.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mongo -port 27117<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">use ace<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">List all the devices on the controller<\/h2>\n\n\n\n<p>This command will list all the devices on the controller.  Regardless of which site they are assigned to.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">db.device.find({}, { site_id:\"\", ip : \"\", name :\"\", mac:\"\"})<\/pre>\n\n\n\n<p>Example output<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ \"_id\" : ObjectId(\"563a4d94e4b054e5376fc600\"), \"mac\" : { \"_id\" : ObjectId(\"563a4d94e4b054e5376fc600\"), \"mac\" : \"44:d9:e7:34:d1:08\", \"ip\" : \"192.168.1.200\", \"name\" : \"Main_WiFi\", \"site_id\" : \"39485e9abf0e9a047bcded96\" }\n{ \"_id\" : ObjectId(\"9873b39ed1f5d30a6738abe\"), \"mac\" : \"44:d9:e7:01:a3:d4\", \"ip\" : \"192.168.1.201\", \"name\" : \"Testing_Wifi\", \"site_id\" : \"39485e9abf0e9a047bcded96\" }<\/pre>\n\n\n\n<p>Each UniFi will have a &#8220;site_id&#8221;.  You can use that ID to figure out which site it is assigned to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">List all the sites on the controller<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">db.site.find()<\/pre>\n\n\n\n<p>Example output<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{ \"_id\" : ObjectId(\"39485e9abf0e9a047bcded96\"), \"name\" : \"default\", \"desc\" : \"Testing Site\", \"attr_hidden_id\" : \"default\", \"attr_no_delete\" : true, \"anonymous_id\" : \"83ae20ba-2948-458e-fd0a-1320583ecb04\" }<\/pre>\n\n\n\n<p>Using our &#8220;site_id&#8221; from above, we see that the Testing_Wifi device is assigned to the &#8220;Testing Site&#8221; on the controller.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Something else to look at would be to use the UniFi controller API.  <\/p>\n\n\n\n<p><a href=\"https:\/\/ubntwiki.com\/products\/software\/unifi-controller\/api\">https:\/\/ubntwiki.com\/products\/software\/unifi-controller\/api<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While the UniFi controller is nice and everything, it does make it hard to see if a device is already adopted. At least if you have a ton of sites. Fortunately, we can search the database directly to find out &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/searching-for-devices-in-unifi-via-command-line-mongodb\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[979,1275],"tags":[1293,371,375,131,132,974,188,114],"class_list":["post-4422","post","type-post","status-publish","format-standard","hentry","category-unifi","category-unifi-protect","tag-ace","tag-mongo","tag-mongodb","tag-ubiquiti-2","tag-ubnt","tag-ui","tag-unifi","tag-wifi"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=4422"}],"version-history":[{"count":2,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4422\/revisions"}],"predecessor-version":[{"id":4424,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4422\/revisions\/4424"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=4422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=4422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=4422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}